home *** CD-ROM | disk | FTP | other *** search
- Path: rcp6.elan.af.mil!rscernix!danpop
- From: danpop@mail.cern.ch (Dan Pop)
- Newsgroups: comp.lang.c
- Subject: Re: sscanf bug??????
- Date: 23 Feb 96 01:17:57 GMT
- Organization: CERN European Lab for Particle Physics
- Message-ID: <danpop.825038277@rscernix>
- References: <4fimvo$82s@fnord.dfw.net> <10FEB199622213548@erich.triumf.ca> <824160515snz@genesis.demon.co.uk> <4gh6uf$i2@mailhub.scitec.com.au> <06R9B8G@gellbo.gellrich-gmbh.de>
- NNTP-Posting-Host: ues5.cern.ch
- X-Newsreader: NN version 6.5.0 #7 (NOV)
-
- In <06R9B8G@gellbo.gellrich-gmbh.de> wolfi@gellbo.gellrich-gmbh.de (Wolfgang Formann) writes:
-
- >In <4gh6uf$i2@mailhub.scitec.com.au> ramsesy@rd.scitec.com.au (Ramses Youhana) writes:
- >
- >>You need the %ld for 16 bit processors or processors running in 16 bit mode.
- >>Unfortunately, your stuck with this when using a PC (using 16 bit mode).
- >>With 32 bit processors (such as a M68302 micro-controller) you don't need
- >>the %ld.
-
- BULLSHIT!!!
-
- >>%d will do as the processor treats the number as a 32 bit entity
- >>anyway. You have to be careful when saying that %ld and %d are interchangeable,
-
- Even better, never say such nonsense. %d and %ld aren't and have never
- been interchangeable. That is, not in C.
-
- >>as a compiler for a 32 bit processor (such as the M68302) may not support the
- >>"l" in the %ld format.
-
- More bullshit. %ld is a standard feature of K&R and ANSI C. A compiler
- which doesn't support it is not a C compiler.
-
- >Well until DEC's Alpha was released I thought the same. I did not write the
- >'l' in '%ld'. But then I had to port some of my code to this 64-bit
- >architecture. It was horrible!
-
- You got exactly what you deserved. You've learned the hard way the
- difference between correct code and broken code that happens to "work"
- on a certain platform with a certain compiler.
-
- >So, if you plan to use your programs *ONLY* on 32-bit processors, then there
- >is no need to write the 'l', but I am sure the 64-bitters will come sooner
- >as we all do think and then the 'l' will be a *MUST*.
-
- The 'l' has _always_ been a must. Using %d for a long variable invokes
- undefined behaviour and it is plain silly to make _any_ kind of speculations
- about the behaviour of a program invoking undefined behaviour.
-
- BTW, even if int and long are the same size, a smart compiler can detect
- and complain about code which uses %d and %ld "interchangeably":
-
- ues5:~/tmp 575> cat test.c
- #include <stdio.h>
-
- int main()
- {
- int i;
- long l;
-
- scanf("%d %ld", &l, &i);
- return printf("%d %ld\n", l, i);
- }
- ues5:~/tmp 576> gcc -Wall test.c
- test.c: In function `main':
- test.c:8: warning: int format, different type arg (arg 2)
- test.c:8: warning: long int format, different type arg (arg 3)
- test.c:9: warning: int format, different type arg (arg 2)
- test.c:9: warning: long int format, different type arg (arg 3)
-
- Dan
- --
- Dan Pop
- CERN, CN Division
- Email: danpop@mail.cern.ch
- Mail: CERN - PPE, Bat. 31 R-004, CH-1211 Geneve 23, Switzerland
-